home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d8 / tm211_2.arc / HOST.EXE / HOST.SCR < prev    next >
Text File  |  1990-05-25  |  19KB  |  658 lines

  1. ;
  2. ; HOST.SCR by Tsung Hu, 21 May, 1990
  3. ;
  4.  
  5. ;
  6. ; constant
  7. ;
  8. TRUE = 1
  9. FALSE = 0
  10. FOREVER = TRUE
  11. FILEDIR = "\HOST.DIR"        ; temp. file for F)ile command
  12.  
  13. ;
  14. ; global variable
  15. ;
  16. integer local,userlevel,exist,xport
  17. string username,password,filename,ch
  18. integer NEWUSERLEVEL,SYSOPLEVEL,DETECTBAUD,INITIALBAUD,YELLTIME,YELLSOUND
  19. string HOSTDIR,DOWNLOADDIR
  20.  
  21.  
  22.    procedure HostConfig         ; read the configuration file
  23.    string s,ch                  ; HCONFIG.HST from the current directory
  24.    open "HCONFIG.HST"
  25.    if success
  26.       read s
  27.       atoi s,NEWUSERLEVEL       ; new user level
  28.       read s
  29.       atoi s,SYSOPLEVEL         ; sysop level
  30.       read s
  31.       atoi s,DETECTBAUD         ; detect baud rate
  32.       read s
  33.       atoi s,INITIALBAUD        ; initial baud rate
  34.       read s
  35.       atoi s,YELLTIME           ; yell time
  36.       read s
  37.       atoi s,YELLSOUND          ; yell sound
  38.       read HOSTDIR              ; directory containing H*.HST
  39.       read DOWNLOADDIR          ; download directory
  40.                                 ; (upload always go to Telemate
  41.                                 ;  downlaod directory)
  42.       close
  43.       set alarmtime,YELLTIME    ; setup yell alarm
  44.       set alarmsound,YELLSOUND
  45.    else
  46.       print "Cannot open HCONFIG.HST in the current directory"
  47.       print
  48.       print "Do you want to setup host mode (y/n)? ",
  49.       repeat
  50.          inputch ch
  51.       until success
  52.       if ch="y"
  53.          print ch
  54.          script "hconfig"       ; chain to HCONFIG.SCR
  55.       else
  56.          print "n"              ; abort host mode
  57.          print "Host mode aborted"
  58.          stop
  59.       endif
  60.    endif
  61.    endproc
  62.  
  63.    procedure HostBegin
  64.    set zautodownload,off
  65.    set zrecovery,off
  66.    set baud,INITIALBAUD
  67.    clear key                            ; clear keyboard buffer
  68.    clear com                            ; clear com buffer
  69.    clear text
  70.    print
  71.    print "Initializing modem"
  72.    put "^)","~ATQ0E0X4^M~",             ; send modem answer string
  73.    print
  74.    print
  75.    print "Host mode, waiting for call"
  76.    print
  77.    print "Press 'L' for local mode, 'C' for configuration,"
  78.    print "      [Esc] to exit and [Alt-H] to terminate user."
  79.    print
  80.    clear key                            ; clear keyboard buffer
  81.    clear com                            ; clear com buffer
  82.    endproc
  83.  
  84.    procedure HostEnd
  85.    set zautodownload,on
  86.    set zrecovery,on
  87.    clear key                            ; clear keyboard buffer
  88.    clear com                            ; clear com buffer
  89.    print
  90.    print "Ending host mode"
  91.    put "^(","~",                        ; send modem init string
  92.    print
  93.    chdir HOSTDIR
  94.    delete FILEDIR                       ; delete temp file
  95.    stop
  96.    endproc
  97.  
  98.    procedure Disconnect                 ; end session
  99.    delay 10
  100.    if not local
  101.       hangup
  102.    endif
  103.    set connection,modem
  104.    local = FALSE
  105.    endproc
  106.  
  107.    procedure Output string s
  108.    print s,
  109.    if not local
  110.       put s,
  111.    endif
  112.    endproc
  113.  
  114.    procedure InputChar string ch        ; input and display locally
  115.    repeat
  116.       if not local
  117.          getch ch
  118.       endif
  119.       if local or not success
  120.          inputch ch
  121.          if success
  122.             if ch = "^["
  123.                HostEnd                  ; abort by operator
  124.             endif
  125.             print ch,
  126.          endif
  127.       endif
  128.    until success or not connected
  129.    endproc
  130.  
  131.    procedure InputEcho string ch        ; input and echo to remote
  132.    InputChar ch
  133.    if not local
  134.       put ch,
  135.    endif
  136.    if ch = "^M"                         ; add line feed
  137.       Output "^J"
  138.    endif
  139.    endproc
  140.  
  141.    procedure DotEcho string ch          ; input and echo "." to remote
  142.    InputChar ch
  143.    if not local
  144.       if ch="^H" or ch="^M"
  145.          put ch,
  146.       else
  147.          put ".",                       ; echo with "."
  148.       endif
  149.    endif
  150.    if ch = "^M"                         ; add line feed
  151.       Output "^J"
  152.    endif
  153.    endproc
  154.  
  155.    procedure InputString string str     ; input a string
  156.    string ch
  157.    str = ""
  158.    repeat
  159.       InputEcho ch
  160.       if ch <> "^M"
  161.          if ch = "^H"
  162.             if str = ""
  163.                Output " "
  164.             else
  165.                Output " ^H"
  166.             endif
  167.          endif
  168.          concat str,ch
  169.       endif
  170.    until ch = "^M" or not connected
  171.    if str="" or not connected
  172.       success = FALSE
  173.    else
  174.       success = TRUE
  175.    endif
  176.    endproc
  177.  
  178.    procedure InputFilename string filename,dir
  179.    string name
  180.    integer pos
  181.    InputString name                     ; input a filename
  182.    repeat
  183.       strpos name,":",pos               ;  strip drive part
  184.       if pos>0
  185.          strdel name,1,pos
  186.       endif
  187.    until pos=0 or not connected
  188.    repeat
  189.       strpos name,"\",pos               ; strip directory part
  190.       if pos>0
  191.          strdel name,1,pos
  192.       endif
  193.    until pos=0 or not connected
  194.    if name="" or not connected
  195.       success = FALSE
  196.       filename = ""
  197.    else
  198.       success = TRUE
  199.       filename = dir
  200.       concat filename,"\"               ; concat <dir>
  201.       strpos filename,"\\",pos
  202.       if pos>0
  203.          strdel filename,pos,1          ; avoid root directory"
  204.       endif
  205.       concat filename,name
  206.    endif
  207.    endproc
  208.  
  209.    procedure InputPassword string password ; input password
  210.    password = ""
  211.    repeat
  212.       DotEcho ch
  213.       if ch <> "^M"
  214.          if ch = "^H"
  215.             if password = ""
  216.                Output " "
  217.             else
  218.                Output " ^H"
  219.             endif
  220.          endif
  221.          concat password,ch
  222.       endif
  223.    until ch = "^M" or not connected
  224.    if password="" or not connected
  225.       success = FALSE
  226.    else
  227.       success = TRUE
  228.    endif
  229.    endproc
  230.  
  231.    procedure CheckUser string username,password,integer level,valid
  232.    integer found,pos1,pos2
  233.    string record,name,pass,lev
  234.    strpos username,";",pos1     ; record format: "first last;password#level"
  235.    strpos username,"#",pos2
  236.    if pos1>0 or pos2>0
  237.       valid = FALSE
  238.       return
  239.    endif
  240.    strpos password,";",pos1     ; check password for invalid character
  241.    strpos password,"#",pos2     ;  prevent "#2" etc
  242.    if pos1>0 or pos2>0
  243.       valid = FALSE
  244.       return
  245.    endif
  246.    chdir HOSTDIR
  247.    open "HUSER.HST"             ; passwords in HUSER.HST
  248.    if not success
  249.       create "HUSER.HST"
  250.    endif
  251.    if not success
  252.       Output "System error, please call again later^M^J"
  253.       print "SYSOP: Cannot create HUSER.HST"
  254.       Disconnect
  255.       alarm "SYSOP: Cannot create HUSER.HST, disk full ?"
  256.       return
  257.    endif
  258.    found = FALSE
  259.    read record
  260.    while success and not found
  261.       strpos record,";",pos1    ; get fields from the record
  262.       strpos record,"#",pos2
  263.       if pos1>0 and pos2>0
  264.          substr record,1,pos1-1,name
  265.          substr record,pos1+1,pos2-pos1-1,pass
  266.          if name=username
  267.             found = TRUE
  268.             if pass=password
  269.                valid = TRUE
  270.                substr record,pos2+1,1,lev
  271.                atoi lev,level
  272.             else
  273.                valid = FALSE
  274.             endif
  275.          endif
  276.       endif
  277.       if not found
  278.          read record
  279.       endif
  280.    endwhile
  281.    if not found                 ; new users
  282.       seek -1
  283.       write username,";",password,"#",NEWUSERLEVEL
  284.       level = 1
  285.       valid = TRUE
  286.    endif
  287.    close
  288.    endproc
  289.  
  290.    procedure Pause              ; request a key
  291.    string ch
  292.    Output "Press [Enter] to continue "
  293.    InputEcho ch
  294.    Output "^M^J"
  295.    if ch<>"^M"
  296.       Output "^M^J"
  297.    endif
  298.    endproc
  299.  
  300.    procedure TypeFile string filename,integer more
  301.    string ch                            ; display a file
  302.    integer i
  303.    i = 0
  304.    open filename
  305.    if not success
  306.       Output "File not found.^M^J"
  307.    else
  308.       while success
  309.          inputch ch
  310.          if success and ch = "^C"        ; operator break
  311.             clear com
  312.             Output "^M^J"
  313.             exit
  314.          endif
  315.          if not local
  316.             getch ch
  317.             if success and ch = "^C"     ; caller break
  318.                clear com
  319.                Output "^M^J"
  320.                exit
  321.             endif
  322.          endif
  323.  
  324.          read s                         ; display a line
  325.          Output s
  326.          Output "^M^J"
  327.  
  328.          i = i+1
  329.          if i = 22 and more             ; pause if <more> is TRUE
  330.             i = 0
  331.             Output "-- More --"
  332.             InputChar ch
  333.             if ch = "^C"
  334.                clear com
  335.                Output "^M^J"
  336.                exit
  337.             endif
  338.             Output "^M                    ^M"
  339.          endif
  340.       endwhile
  341.       close
  342.       if more
  343.          Pause
  344.       endif
  345.    endif
  346.    endproc
  347.  
  348.    procedure Directory                  ; display download directory
  349.    string cmd
  350.    cmd = "DIR >"
  351.    concat cmd,FILEDIR                   ; DIR >\HOST.DIR
  352.    dos cmd                              ; shell to DOS
  353.    TypeFile FILEDIR,TRUE                ; display \HOST.DIR
  354.    endproc
  355.  
  356.    procedure FileTransfer string mode,protocol,filename
  357.    print "^M^JPlease start your transfer procedure or press Ctrl-X to abort^M^J"
  358.    if mode = "r"
  359.       if filename=""                    ; receive batch files
  360.          receive protocol
  361.       else
  362.          receive protocol,filename      ; receive single file
  363.       endif
  364.    else
  365.       send protocol,filename            ; send multiple files
  366.    endif
  367.    if success
  368.       Output "File transfer completed^M^J"
  369.    else
  370.       Output "File transfer aborted^M^J"
  371.    endif
  372.    Pause
  373.    endproc
  374.  
  375.    procedure WaitForCall                ; wait for connected
  376.    integer i,len,valid,exist,baudrate
  377.    set connection,modem
  378.    local = FALSE
  379.    xport = FALSE
  380.    while not connected                  ; wait for carrier signal
  381.       inputch ch                        ; sysop commands
  382.       if success
  383.          switch ch
  384.            case "^[":                   ; abort
  385.               HostEnd
  386.            case "L":                    ; local mode
  387.               set connection,computer   ; this will set connected = 1
  388.               local = TRUE
  389.            case "C":                    ; configuration
  390.               script "HCONFIG"          ; chain to HCONFIG.SCR
  391.          endswitch
  392.       endif
  393.    endwhile
  394.    if not local and DETECTBAUD
  395.       waitfor "CONNECT^M","CONNECT 1200","CONNECT 2400","CONNECT 9600","CONNECT 19200",10
  396.       if found
  397.          switch found
  398.             case 1: baudrate = 300
  399.             case 2: baudrate = 1200
  400.             case 3: baudrate = 2400
  401.             case 4: baudrate = 9600
  402.             case 5: baudrate = 19200
  403.          endswitch
  404.          set baud,baudrate
  405.          Output "Connected at "
  406.          if not local
  407.             put baudrate,"^M^J"
  408.          endif
  409.          print baudrate
  410.       endif
  411.    endif
  412.    Output "^M^J"
  413.    delay 5
  414.    clear com
  415.    delay 5
  416.    chdir HOSTDIR
  417.    TypeFile "HWELCOME.HST",FALSE        ; display welcome message
  418.    i = 1
  419.    len = 0
  420.    username = ""                        ; enter name (at most 3 times)
  421.    while i<=3 and len<4 and connected
  422.       Output "Please enter your First and Last name: "
  423.       InputString username
  424.       i = i+1
  425.       length username,len               ; check the length of name
  426.       if len<4
  427.          Output "Name too short, please try again^M^J^M^J"
  428.       else
  429.          Output username
  430.          Output " [Y/n]? "
  431.          InputString ch
  432.          if ch="n"
  433.             len=0
  434.          endif
  435.       endif
  436.    endwhile
  437.    if len<4 and connected
  438.       Output "Goodbye^M^J"
  439.       Disconnect
  440.    else
  441.       i = 1
  442.       len = 0
  443.       password = ""                     ; enter password (at most 3 times)
  444.       while i<=3 and len<4 and connected
  445.          Output "Password: "
  446.          InputPassword password
  447.          i = i+1
  448.          length password,len            ; check the length of ot
  449.          if len<4
  450.             Output "Password too short, please try again^M^J^M^J"
  451.          endif
  452.       endwhile
  453.       if len>=4                         ; check password and get user level
  454.          CheckUser username,password,userlevel,valid
  455.       endif
  456.       if (len<4 or not valid) and connected
  457.          Output "Invalid password, access denied^M^J^M^J"
  458.          Disconnect
  459.       else
  460.          chdir HOSTDIR                  ; display notice
  461.          FileExist "HNOTICE.HST",exist
  462.          if exist
  463.             Output "^M^J"
  464.             TypeFile "HNOTICE.HST",TRUE
  465.          endif
  466.       endif
  467.    endif
  468.    endproc
  469.  
  470.    procedure ChatMode                   ; chat mode
  471.    integer x
  472.    string rch,lch
  473.    Output "^M^JChat mode begin:^M^J"
  474.    repeat
  475.       if not local
  476.          getch rch
  477.          if success
  478.             put rch,
  479.             if rch = "^M"
  480.                Output "^J"
  481.             endif
  482.             wherex x
  483.             if rch = " " and x > 70
  484.                Output "^M^J"
  485.             endif
  486.          endif
  487.       endif
  488.       inputch lch
  489.       if success and lch<>"^["          ; abort if sysop press [Esc]
  490.          Output lch
  491.          if lch = "^M"
  492.             Output "^J"
  493.          endif
  494.          wherex x
  495.          if lch = " " and x > 70
  496.             Output "^M^J"
  497.          endif
  498.       endif
  499.    until lch="^[" or not connected
  500.    Output "^M^JChat mode end.^M^J^M^J"
  501.    Pause
  502.    endproc
  503.  
  504.    procedure DoCommand                  ; do a command
  505.    if xport
  506.       Output "Command F,U,D,T,C,X,G,(S,R,Z): "  ; export mode
  507.    else
  508.       Output "^M^J^M^J"
  509.       chdir HOSTDIR
  510.       TypeFile "HMENU.HST",FALSE        ; display menu
  511.       Output "Command: "
  512.    endif
  513.    InputEcho ch
  514.    if ch<>"^M"
  515.       Output "^M^J"
  516.    endif
  517.    switch ch
  518.       case "F":                         ; file directory
  519.          chdir DOWNLOADDIR
  520.          Directory
  521.       case "T":                         ; type a file
  522.          Output "Enter filename: "
  523.          InputFilename filename,DOWNLOADDIR
  524.          if success
  525.             chdir DOWNLOADDIR
  526.             TypeFile filename,TRUE
  527.          endif
  528.       case "U":                         ; upload a file
  529.          Output "^M^J"
  530.          chdir HOSTDIR
  531.          TypeFile "HPROT.HST",FALSE
  532.          Output "Select protocol: "
  533.          InputEcho protocol
  534.          Output "^M^J"
  535.          if local
  536.             Output "Function not available in local mode^M^J"
  537.          else
  538.             switch protocol
  539.                case "X","R":
  540.                   Output "Enter filename: "
  541.                   InputFilename filename,""
  542.                   if success
  543.                      FileTransfer "r",protocol,filename
  544.                   endif
  545.                case "Z","S","T","M","Y","B","G":
  546.                   FileTransfer "r",protocol,""
  547.             endswitch
  548.          endif
  549.       case "D":                         ; download a file
  550.          Output "^M^J"
  551.          chdir HOSTDIR
  552.          TypeFile "HPROT.HST",FALSE
  553.          chdir DOWNLOADDIR
  554.          Output "Select protocol: "
  555.          InputEcho protocol
  556.          Output "^M^J"
  557.          if local
  558.             Output "Function not available in local mode^M^J"
  559.          else
  560.             switch protocol
  561.                case "X","Y","Z","S","T","M","R","B","G":
  562.                   Output "Enter filename: "
  563.                   InputFilename filename,DOWNLOADDIR
  564.                   if success
  565.                      FileTransfer "s",protocol,filename
  566.                   endif
  567.             endswitch
  568.          endif
  569.      case "C":                          ; yell
  570.          Output "Yelling Sysop, please wait ... ^M^J"
  571.          alarm "User is yelling ...^JPress [Enter] to accept, [Esc] to deny"
  572.          if success
  573.             print "^M^JSYSOP: press [Esc] to terminate chat mode"
  574.             ChatMode
  575.          else
  576.             Output "^M^JSorry, Sysop is not here^M^J"
  577.          endif
  578.       case "X":                         ; toggle export mode
  579.          xport = not xport
  580.       case "G":                         ; goodbye
  581.          chdir HOSTDIR
  582.          TypeFile "HGOODBYE.HST",FALSE
  583.          Disconnect
  584.  
  585.       case "S":                         ; shell to DOS
  586.          if userlevel<SYSOPLEVEL
  587.             Output "Sorry, this command is for Sysop only^M^J"
  588.          else
  589.             chdir HOSTDIR
  590.             if local                    ; local mode shell to DOS
  591.                Output "Shelling to DOS ... ^M^J"
  592.                dos
  593.                Output "Return from DOS shell^M^J"
  594.             else
  595.                fileexist "hshell.bat",exist     ; check for HSHELL.BAT
  596.                if exist
  597.                   Output "Shelling to DOS ... ^M^J"
  598.                   dos "hshell.bat"
  599.                   Output "Return from DOS shell^M^J"
  600.                else
  601.                   Output "SYSOP: Cannot find HSHELL.BAT^M^J"
  602.                endif
  603.             endif
  604.          endif
  605.       case "R":                         ; run remote program
  606.          if userlevel<SYSOPLEVEL
  607.             Output "Sorry, this command is for Sysop only^M^J"
  608.          else
  609.             chdir HOSTDIR
  610.             if local                    ; run HLOCAL.BAT if local mode
  611.                fileexist "hlocal.bat",exist
  612.                if exist
  613.                   Output "Loading external program ... ^M^J"
  614.                   dos "hlocal.bat"
  615.                   Output "Return from external program^M^J"
  616.                else
  617.                   Output "SYSOP: Cannot find HLOCAL.BAT^M^J"
  618.                endif
  619.             else                        ; run HREMOTE.BAT if remote mode
  620.                fileexist "hremote.bat",exist
  621.                if exist
  622.                   Output "Loading remote program ... ^M^J"
  623.                   dos "hremote.bat"
  624.                   Output "Return from remote program^M^J"
  625.                else
  626.                   Output "SYSOP: Cannot find HREMOTE.BAT^M^J"
  627.                endif
  628.             endif
  629.          endif
  630.       case "Z":                         ; shut down host mode
  631.          if userlevel<SYSOPLEVEL
  632.             Output "Sorry, this command is for Sysop only^M^J"
  633.          else
  634.             Output "Are you sure [y/N]? "
  635.             InputString ch
  636.             if ch="y"
  637.                Output "Shutting down host mode^M^J"
  638.                Disconnect
  639.                HostEnd
  640.             endif
  641.          endif
  642.    endswitch
  643.    endproc
  644.  
  645. ;
  646. ; begin main program
  647. ;
  648. HostConfig              ; read configuration file HCONFIG.HST
  649. while FOREVER
  650.    HostBegin            ; initial mode
  651.    WaitForCall          ; wait for a call
  652.    while connected
  653.       DoCommand         ; do commands
  654.    endwhile
  655. endwhile
  656.  
  657.  
  658.